exports.CreateScreenMenuItems=function(_args)
{
	var pathimage=Ti.App.Properties.getString('pathimage');
	var view = Ti.UI.createView({
		 borderColor: Ti.App.Properties.getString('borderColor'),
	     borderRadius: Ti.App.Properties.getInt('borderRadius'),
	     borderWidth:Ti.App.Properties.getInt('borderWidth'),
		width:_args.width,
		height:_args.height,
		backgroundColor: _args.backgroundColor,
		top:0,
		left:_args.left,
		
	})
	
	//////////////////NUMBER PAD///////////
	var platformWidth=Titanium.Platform.displayCaps.platformWidth;//Ti.App.Properties.getInt('platformWidth');
	var platformHeight=Titanium.Platform.displayCaps.platformHeight;//Ti.App.Properties.getInt('platformHeight');
	var btnumber_width=_args.width/4;
	var btnumber_height=Ti.App.Properties.getInt('Order_buttonnumber_height')
	var bottom_row1=0;
	var bottom_row2=btnumber_height;
	var bottom_row3=2*btnumber_height;
	var bottom_row4=3*btnumber_height;
	
	var left_col1=0;
	var left_col2=btnumber_width;
	var left_col3=2*btnumber_width;
	
	var bts=[
		{title:',',value:-1,func:'',bottom:bottom_row1,left:left_col1},
		{title:0,value:0,func:'',     bottom:bottom_row1,left:left_col2},
		{title:'X',value:-2,func:'',bottom:bottom_row1,left:left_col3},
		{title:7,value:7,func:'',	  bottom:bottom_row2,left:left_col1},
		{title:8,value:8,func:'',     bottom:bottom_row2,left:left_col2},
		{title:9,value:9,func:'',     bottom:bottom_row2,left:left_col3},
		{title:4,value:4,func:'',     bottom:bottom_row3,left:left_col1},
		{title:5,value:5,func:'',     bottom:bottom_row3,left:left_col2},
		{title:6,value:6,func:'',     bottom:bottom_row3,left:left_col3},
		{title:1,value:1,func:'',     bottom:bottom_row4,left:left_col1},
		{title:2,value:2,func:'',     bottom:bottom_row4,left:left_col2},
		{title:3,value:3,func:'',     bottom:bottom_row4,left:left_col3},
		
	]
	var createButtonNumberPad = function (bt) {
		var bt = Titanium.UI.createButton({
			 borderColor: Ti.App.Properties.getString('borderColor'),
		     borderRadius: Ti.App.Properties.getInt('borderRadius'),
		     borderWidth:Ti.App.Properties.getInt('borderWidth'),
		     value:bt.value,
			 color:'Black',
			
			 title:bt.title,
			 backgroundImage:pathimage+'tb2.png',
			 backgroundSelectedImage:pathimage+'bt_Nau_press.png',
			
			 width:btnumber_width,
		 	 height:	btnumber_height,
		   	 bottom:bt.bottom,
		   	 left:bt.left,
		   	 font:{
				fontSize:Ti.App.Properties.getInt('MainWindow_btnumber_fontsize'),
				fontWeight:'bold',
		 	 },
	   	 	 
		}); 
		bt.addEventListener('click', function (e) {
			Ti.API.info(e.source.title)
			Ti.API.info(txtQuantity.text)
			if(e.source.title==='X')
				txtQuantity.text='';
			else if(e.source.title===',')
				txtQuantity.text='';
			else
			{
				//txtQuantity.text=txtQuantity.text+e.source.title
				var a=txtQuantity.text
				if(a==null) a='';
				txtQuantity.text=a+e.source.title
			}
				
        })
		return bt;
	}
	
	for (i = 0; i < bts.length; i++){
        var btadd=createButtonNumberPad(bts[i])
       
		view.add(btadd);
    }
	
	///////////PAD Search.//////////////
	var bottom_SEARCH=(bottom_row4+btnumber_height)/3
	var height_SEARCH=(bottom_row4+btnumber_height)/3
	var bts_Search=[
		{title:'Tìm bàn',value:-1,func:'',bottom:0},
		{title:'Tìm phiếu',value:0,func:'',     bottom:bottom_SEARCH},
		{title:'Tìm T đơn',value:-2,func:'',bottom:2*bottom_SEARCH},
	]
	var createButtonSearch = function (bt) {
		var bt = Titanium.UI.createButton({
			 borderColor: Ti.App.Properties.getString('borderColor'),
		     borderRadius: Ti.App.Properties.getInt('borderRadius'),
		     borderWidth:Ti.App.Properties.getInt('borderWidth'),
		     
			 color:'Black',
			
			 title:bt.title,
			 backgroundImage:pathimage+'tb2.png',
			 backgroundSelectedImage:pathimage+'bt_Nau_press.png',
			
			 width:btnumber_width,
		 	 height:	height_SEARCH,
		   	 bottom:bt.bottom,
		   	 right:0,
		   	 font:{
				fontSize:20,
				fontWeight:'bold',
		 	 },
	   	 	 
		}); 
		bt.addEventListener('click', function (e) {
			//Ti.App.fireEvent('TableWindow:locationSelect',{data:e.source.id});
        })
		return bt;
	}
	
	for (i = 0; i < bts_Search.length; i++){
        var btadd_search=createButtonSearch(bts_Search[i])
       
		view.add(btadd_search);
    }
	/////////////TEXTBOX///////////
	var txtQuantity = Titanium.UI.createLabel({
		borderColor: Ti.App.Properties.getString('borderColor'),
	    borderRadius: Ti.App.Properties.getInt('borderRadius'),
	    borderWidth:Ti.App.Properties.getInt('borderWidth'),
		color:'Black',
		
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		
		//enabled:false,
	    keyboardType: Titanium.UI.KEYBOARD_DEFAULT,
	    returnKeyType: Titanium.UI.RETURNKEY_SEARCH , 
		textAlign:'center',
		hintText:'',
		left:0,
		bottom:4*btnumber_height,
		height:btnumber_height,
		width:_args.width-btnumber_width,
	 	font:{
			fontSize:Ti.App.Properties.getInt('MainWindow_btnumber_fontsize'),
			fontWeight:'bold',
		 },
	}); 
	/*
	txtpassword.addEventListener('change', function (e) {
			Ti.API.info(txtpassword.value+e.value)
        	txtpassword.value=txtpassword.value+e.value
    })
    */
	view.add(txtQuantity)
	var btC = Titanium.UI.createButton({
		 borderColor: Ti.App.Properties.getString('borderColor'),
	     borderRadius: Ti.App.Properties.getInt('borderRadius'),
	     borderWidth:Ti.App.Properties.getInt('borderWidth'),
	  
		 color:'Black',
		
		 title:'C',
		 backgroundImage:pathimage+'tb2.png',
		 backgroundSelectedImage:pathimage+'bt_Nau_press.png',
		
		 right:0,
		 bottom:4*btnumber_height,
		 height:btnumber_height,
		 width:btnumber_width,
	   	 font:{
			fontSize:20,
			fontWeight:'bold',
	 	 },
   	 	 
	}); 
	btC.addEventListener('click', function (e) {
		
    	txtQuantity.text=''
    })
	view.add(btC)
	
	
	
	///////////////TABLE VIEW////////////////////////////////////////////////////
	var tableview = Ti.UI.createTableView({
		width:_args.width,
		height:platformHeight-5*btnumber_height,
		backgroundColor: 'Transparent',
		top:0,
		left:0,
		separatorColor:'Transparent',
	})
	view.add(tableview)
	var col_in=2;
	var tableviewrow_height=Ti.App.Properties.getInt('Order_buttonnumber_height')
	var tableviewrow_width=tableview.width/col_in;
	
	
	
	
	var LoadScreenMenuItems_Data = function(ScreenMenuCategoryId) {
 		var json=require('db').selectScreenMenuItems(ScreenMenuCategoryId);
		return json;
    }
	var createButton = function (bt,left) {
		
		var bt = Titanium.UI.createButton({
			
			 borderColor: Ti.App.Properties.getString('borderColor'),
		     borderRadius: Ti.App.Properties.getInt('borderRadius'),
		     borderWidth:Ti.App.Properties.getInt('borderWidth'),
			 color:'Black',
			 Id:bt.Id,
			 Name:bt.Name,
			 Price_Amount:bt.Price_Amount,
			 ScreenMenuCategoryId:bt.ScreenMenuCategoryId,
			 title:bt.Name,
			 backgroundImage:pathimage+'bt_Green.png',//pathimage+'table.png',
			 backgroundSelectedImage:pathimage+'table.png',
			 width:tableviewrow_width,
		 	 height:tableviewrow_height,
		   	 left:left,
		   	 Item:bt,
		   	 font:{
				fontSize:20//Ti.App.Properties.getInt('MainWindow_btnumber_fontsize'),
				//fontWeight:'bold',
		 	 },
	   	 	 
		}); 
		bt.addEventListener('click', function (e) {
			var Quantity=1
			if(txtQuantity.text!=''&&txtQuantity.text!=null)
				Quantity=txtQuantity.text
			txtQuantity.text=''
			Ti.App.fireEvent('OrderWindow:SelectItems',{Name:e.source.Name,
														Id:e.source.Id,
														Quantity:Quantity,
														Price_Amount:e.source.Price_Amount,
														Item:e.source.Item
														});
        })
		return bt;
	}
	var CreateTableViewRow = function(e) {
		//Ti.API.info(e.data.id)
		var item=e.data;
		
		//Ti.API.info('KKLLLLLLL'+item)
		//if(item==null) return;
		//Ti.API.info(item)
		var row = Ti.UI.createTableViewRow({
	            height:tableviewrow_height,
				//Table_Id:item.Table_Id,
				//TableScreen_Id:item.TableScreen_Id,
				//Name:item.Name
		})
	
		var left_bt=0;
		for (var c=0;c<item.length;c++){
			//Ti.API.info('CAO '+item[c])
			if(item[c]!=undefined)
			{
				var bt=createButton(item[c],left_bt)
				row.add(bt);
				left_bt+=tableviewrow_width;
			}
			
		}
		return row;
	}
	
	
	var LoadScreenMenuItems = function(ScreenMenuCategoryId) {
    	
 		var tableData=[];
 		var json=[];
 		
 		if (Ti.App.Properties.getInt('IsDemo')==1) 
 		{
 			json=LoadScreenMenuItems_Data(ScreenMenuCategoryId);
 		}
 		else
 		{
 			//json=LoadListDataLocal(e);
 		}
 		
 		//Ti.API.info ('Chieu dai'+json.length)
 		/*
 		if (json.length==0) {
 			require('settings').Alert_error(win,Globals.connect_pop);
 		}else
 		*/
 		require('settings').LoadedData2TableView(tableview,json,CreateTableViewRow,col_in);
	};
	LoadScreenMenuItems(16)
	
	_args.egc.addEventListener('OrderWindow:ChangeScreenMenuCategories', function (e) {
		LoadScreenMenuItems(e.data)
	})
	_args.egc.addEventListener('ScreenMenuItems:ChangeTableExcute', function (e) {
	
		_args.TablesId=e.TableId_New
		
	})
	
	return view;
}
